package com.itheima.exerciseTest.method20_29.method27;

import java.util.concurrent.Semaphore;

public class SemaphoreDemo implements Runnable {
    // 创建Semaphore对象
    Semaphore semaphore = new Semaphore(3);

    @Override
    public void run() {
        try {
            // 获得通行证
            semaphore.acquire();
            System.out.println("获得通行证");
            // 收回通行证
            semaphore.release();
            System.out.println("收回通行证\n");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
